package com.inibb.app.validator;

import java.util.Iterator;
import java.util.Set;

import javax.validation.ConstraintViolation;

import com.inibb.app.exception.ServiceVLDException;





public class JpaValidatorHelper {

	public static <T> ServiceVLDException convertToException(Set<ConstraintViolation<T>> errs, Object target, String objectName){
		ServiceVLDException error = new ServiceVLDException(target, objectName);
		Iterator<ConstraintViolation<T>> iter = errs.iterator();
		while(iter.hasNext()){
			ConstraintViolation<T> o = iter.next();
			error.rejectValue(o.getPropertyPath().toString(), o.getMessage(), o.getMessage());
		}
		return error;
		
	}
}
